﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package reprise.controls {
    import flash.events.*;
    import reprise.css.*;
    import reprise.core.*;
    import reprise.utils.*;
    import flash.text.*;

    public class TextInput extends Label {

        protected var m_verticalScrollingOn:Boolean;
        protected var m_labelStr:String;// = ""
        protected var m_horizontalScrollingOn:Boolean;
        protected var m_placeholder:String;
        protected var m_enabled:Boolean;

        public static const className:String = "TextInput";

        public function setDisplaysAsPassword(_arg1:Boolean):void{
            m_labelDisplay.displayAsPassword = _arg1;
        }
        override public function get enabled():Boolean{
            return (m_enabled);
        }
        override public function didSucceed():Boolean{
            if (((((m_validator) || (!(m_required)))) || (!(m_placeholder)))){
                return (super.didSucceed());
            };
            var _local1 = !((value() == m_placeholder));
            if (_local1){
                markAsValid();
            } else {
                markAsInvalid();
            };
            return (_local1);
        }
        override public function getLabel():String{
            return (m_labelStr);
        }
        override public function set enabled(_arg1:Boolean):void{
            if (_arg1 == m_enabled){
                return;
            };
            m_enabled = _arg1;
            if (!_arg1){
                addCSSPseudoClass("disabled");
                m_labelDisplay.type = "dynamic";
            } else {
                removeCSSPseudoClass("disabled");
                m_labelDisplay.type = "input";
            };
            invalidate();
        }
        override protected function renderLabel():void{
            var _local1:int = m_labelDisplay.selectionBeginIndex;
            var _local2:int = m_labelDisplay.selectionEndIndex;
            m_labelXML = <p>[[!]]</p>
            ;
            m_labelDisplay.styleSheet = CSSDeclaration.TEXT_STYLESHEET;
            super.renderLabel();
            var _local3:TextFormat = m_labelDisplay.getTextFormat();
            m_labelDisplay.styleSheet = null;
            m_labelDisplay.defaultTextFormat = _local3;
            m_labelDisplay.text = ((m_labelStr) || (""));
            m_labelDisplay.setSelection(_local1, _local2);
            m_labelDisplay.width = (calculateContentWidth() + 4);
            m_labelDisplay.height = (calculateContentHeight() + 4);
        }
        override protected function initialize():void{
            super.initialize();
            m_canBecomeKeyView = true;
            m_enabled = true;
        }
        protected function label_textInput(_arg1:TextEvent):void{
            var _local3:int;
            var _local4:int;
            _arg1.preventDefault();
            var _local2:String = _arg1.text;
            if (m_labelDisplay.maxChars){
                _local2 = _arg1.text.substr(0, (((m_labelDisplay.maxChars - m_labelDisplay.length) + m_labelDisplay.selectionEndIndex) - m_labelDisplay.selectionBeginIndex));
                if (!_local2){
                    return;
                };
            };
            if (m_currentStyles.textTransform == "uppercase"){
                _local2 = _local2.toUpperCase();
            } else {
                if (m_currentStyles.textTransform == "lowercase"){
                    _local2 = _local2.toLowerCase();
                };
            };
            m_labelDisplay.replaceSelectedText(_local2);
            if (m_currentStyles.textTransform == "capitalize"){
                _local3 = m_labelDisplay.selectionBeginIndex;
                _local4 = m_labelDisplay.selectionEndIndex;
                m_labelDisplay.text = StringUtil.toTitleCase(m_labelDisplay.text);
                m_labelDisplay.setSelection(_local3, _local4);
            };
            m_labelDisplay.dispatchEvent(new Event(Event.CHANGE, true));
        }
        override protected function initDefaultStyles():void{
            super.initDefaultStyles();
            m_elementDefaultStyles.setStyle("multiline", "false");
            m_elementDefaultStyles.setStyle("display", "block");
            m_elementDefaultStyles.setStyle("wordWrap", "false");
            m_elementDefaultStyles.setStyle("height", "18px");
            m_elementDefaultStyles.setStyle("padding", "2px");
        }
        override protected function applyOverflowProperty():void{
            if (((!(((m_labelDisplay.maxScrollV > 1) == m_verticalScrollingOn))) || (!(((m_labelDisplay.maxScrollH > 0) == m_horizontalScrollingOn))))){
                m_overflowIsInvalid = true;
                super.applyOverflowProperty();
                m_verticalScrollingOn = (m_labelDisplay.maxScrollV > 1);
                m_horizontalScrollingOn = (m_labelDisplay.maxScrollH > 0);
            };
        }
        override public function setFocus(_arg1:Boolean, _arg2:String):void{
            var _local3:int;
            super.setFocus(_arg1, _arg2);
            if (_arg1){
                stage.focus = m_labelDisplay;
                if (getLabel() == m_placeholder){
                    removeCSSClass("placeholder");
                    setLabel("");
                };
                if (_arg2 == FocusManager.FOCUS_METHOD_KEYBOARD){
                    m_labelDisplay.setSelection(0, m_labelDisplay.length);
                } else {
                    if (m_labelDisplay.length){
                        _local3 = m_labelDisplay.getCharIndexAtPoint(m_labelDisplay.mouseX, m_labelDisplay.mouseY);
                        if (_local3 == -1){
                            _local3 = m_labelDisplay.length;
                        };
                        m_labelDisplay.setSelection(_local3, _local3);
                    };
                };
            } else {
                if (((m_placeholder) && (!(m_labelDisplay.length)))){
                    setLabel(m_placeholder);
                };
                if (m_labelStr == m_placeholder){
                    addCSSClass("placeholder");
                };
            };
        }
        override protected function createChildren():void{
            super.createChildren();
            m_labelDisplay.type = "input";
            m_labelDisplay.mouseEnabled = true;
            m_labelDisplay.addEventListener(Event.CHANGE, label_change);
        }
        public function getPlaceholderAttribute():String{
            return (m_placeholder);
        }
        protected function label_change(_arg1:Event):void{
            m_labelStr = m_labelDisplay.text;
            _arg1.stopImmediatePropagation();
            _arg1.stopPropagation();
            dispatchEvent(new Event(Event.CHANGE));
            applyOverflowProperty();
        }
        public function setPlaceholderAttribute(_arg1:String):void{
            m_placeholder = _arg1;
            if (!m_labelStr){
                setLabel(_arg1);
            };
        }
        override public function setValue(_arg1):void{
            setLabel(_arg1);
        }
        override protected function applyStyles():void{
            super.applyStyles();
            if (((m_currentStyles.inputCharRestrict) && (!((m_currentStyles.inputCharRestrict == "none"))))){
                m_labelDisplay.restrict = m_currentStyles.inputCharRestrict;
            } else {
                m_labelDisplay.restrict = null;
            };
            m_labelDisplay.maxChars = ((m_currentStyles.inputLengthRestrict) || (0));
            if (((m_currentStyles.textTransform) && (!((m_currentStyles.textTransform == "none"))))){
                m_labelDisplay.addEventListener(TextEvent.TEXT_INPUT, label_textInput);
            } else {
                m_labelDisplay.removeEventListener(TextEvent.TEXT_INPUT, label_textInput);
            };
        }
        override public function setLabel(_arg1:String):void{
            if ((((_arg1 == null)) && (m_placeholder))){
                _arg1 = m_placeholder;
            };
            if (_arg1 == m_placeholder){
                addCSSClass("placeholder");
            } else {
                removeCSSClass("placeholder");
            };
            m_labelStr = _arg1;
            m_labelDisplay.text = _arg1;
            invalidate();
        }
        override protected function parseXMLContent(_arg1:XMLList):void{
        }
        override protected function updateHover(_arg1:Boolean=false):void{
            if (((!(stage)) || ((stage.focus == m_labelDisplay)))){
                return;
            };
            super.updateHover(_arg1);
        }
        public function getValue():Object{
            return (((getLabel() == m_placeholder)) ? "" : getLabel());
        }
        public function displaysAsPassword():Boolean{
            return (m_labelDisplay.displayAsPassword);
        }

    }
}//package reprise.controls 
